class LtftsController < ApplicationController
  
  before_filter :ini_ref
  
  def ini_ref
    @ltfls = Ltfl.find :all  
  end
  
  def index
    @ltfts = Ltft.find(:all,:conditions => [ "flmc = ? or xtfl = ?",params[:flmc],9],:order =>["xtfl desc ",",created_at DESC"])

  end
  def new
    @ltft = Ltft.new
  end
  def create
    @ltft = Ltft.new(params[:ltft])
      if @ltft.save
        #flash[:notice] = '添加新用户成功.'
        #
        redirect_to("/ltfts?flmc="+@ltft.flmc)
#        self.redirect_to "/ltfts"
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @ltft.errors, :status => :unprocessable_entity }
      end
   end
   
   
   def edit
    @ltft = Ltft.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @ltft }
    end
   end
   
   def show
    @ltft = Ltft.find(params[:id])
    @lthfs = @ltft.lthfs.find(:all)
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @ltft }
    end
   end
   
   def create_lthf
     @lthf = Lthf.new(params[:lthf])
     @lthf.ltft = @ltft
     respond_to do |format|
        if @lthf.save
          flash[:notice] = '发表回复成功.'
          format.html { redirect_to ltft_url(@ltft)}
#          format.xml  { render :xml => @file_image, :status => :created, :location => @file_image }
        else
          format.html { render :action => "new"}
#          format.xml  { render :xml => @file_image.errors, :status => :unprocessable_entity }
        end
      end
   end
   def update
     @lthf = Lthf.new(params[:lthf])
     @ltft = Ltft.find(params[:ltft_id])
     @lthf.ltft = @ltft
 
     respond_to do |format|
        if @lthf.save
          flash[:notice] = '发表回复成功.'
          format.html { redirect_to ltft_url(@ltft)}
#          format.xml  { render :xml => @file_image, :status => :created, :location => @file_image }
        else
          format.html { render :action => "new"}
#          format.xml  { render :xml => @file_image.errors, :status => :unprocessable_entity }
        end
      end
   end
end
